package com.chixing.day15_map.homework;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Student {
//    private int stuNo;
//    private String stuName;
//    private int stuGender;  //性别
//    private String stuMajor; //专业
//    private LocalDate stuBirthday;


    public static void main(String[] args) throws IOException {
        List<Student> list = readExcelData("student.xls");
    }
    public static List<Student> readExcelData(String fileName) throws IOException {
        //用字节流的方式先读取到你想要的excel的文件
        FileInputStream fis=new FileInputStream(new File("D://test1/student.xls"));

        //解析excel
        POIFSFileSystem pSystem=new POIFSFileSystem(fis);
        //获取整个excel
        HSSFWorkbook hb=new HSSFWorkbook(pSystem);
        //获取第一个表单sheet
        HSSFSheet sheet=hb.getSheetAt(0);
        //获取第一行  从0开始
        int firstrow=sheet.getFirstRowNum();
        //获取最后一行
        int lastrow=sheet.getLastRowNum();
        //循环行数依次获取列数
        List<String> list=new ArrayList<>();
        for (int i = firstrow; i < lastrow+1; i++) {//循环行数
            //获取哪一行i
            Row row=sheet.getRow(i);
            if (row!=null) {
                //获取这一行的第一列 从0开始
                int firstcell=    row.getFirstCellNum();
                //获取这一行的最后一列
                int lastcell=    row.getLastCellNum();
                //创建一个集合，用处将每一行的每一列数据都存入集合中

                for (int j = firstcell; j <lastcell; j++) {//循环列数
                    //获取第j列
                    Cell cell=row.getCell(j);
                    if (cell!=null) {
                        System.out.print(cell+"\t");
                        list.add(cell.toString());
                    }
                }
                System.out.println();
            }
        }
        fis.close();
        return null;
    }
}
